<?php
/*
	$Id: admincp_contribute.php 12844 2012-08-21 gy $
*/

if(!defined('IN_UCHOME') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

//权限
if(!$allowmanage = checkperm('managearctype')) {
	cpmessage('no_authority_management_operation');
}


if(!empty($_POST['op'])&&$_POST['op']=='add'){
	$data['typename'] = trim($_POST['typename']);
	$data['hide'] = intval($_POST['hide']);
	$data['reid'] = intval($_POST['reid']);
	$data['tptime'] = time();
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('arctype')." WHERE lid =".$data['reid']);
	$da = $_SGLOBAL['db']->fetch_array($query);
	$data['topid'] = $da['topid'];
	$insert = inserttable('arctype',$data,1);
	if($insert){
		cpmessage('arctype_success', 'admincp.php?ac=arctype');
	}else{
		cpmessage('arctype_fail', 'admincp.php?ac=arctype');
	}
}

if(!empty($_POST['op'])&&$_POST['op']=='edit'){
	$typename = trim($_POST['typename']);
	$hide = intval($_POST['hide']);
	$lid = intval($_POST['lid']);
	updatetable('arctype', array('typename'=>$typename,'hide'=>$hide), array('lid'=>$lid));
	cpmessage('do_success', 'admincp.php?ac=arctype');
}

if($_GET['op'] == 'add') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$actives = array('add' => 'class="active"');
	$reid = intval($_GET['reid']);
	$op = $_GET['op'];
}elseif($_GET['op'] == 'edit') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$actives = array('edit' => 'class="active"');
	$lid = intval($_GET['lid']);
	$op = $_GET['op'];
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('arctype')." WHERE lid =".$lid);
	$ap = $_SGLOBAL['db']->fetch_array($query);
}elseif($_GET['op'] == 'del') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	$lid = intval($_GET['lid']);
	$_SGLOBAL['db']->query("DELETE FROM ".tname('arctype')." WHERE lid=".$lid);
	cpmessage('do_success', 'admincp.php?ac=arctype');
}else{
	$actives = array('all' => 'class="active"');
	$html = "";
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('arctype')." WHERE reid = 0 ");
	while($value = $_SGLOBAL['db']->fetch_array($query)) {
		$seid = $value['lid'];
		$html .="<li><span>".$value['typename']."(ID:".$seid.")</span>|<a href='admincp.php?ac=arctype&op=add&reid=".$value['lid']."'>添加子栏目</a>|<a href='admincp.php?ac=arctype&op=edit&lid=".$value['lid']."'>修改栏目</a>|<a class='del' ref='admincp.php?ac=arctype&op=del&lid=".$value['lid']."'>删除栏目</a>|";
		Datas($seid);
		$html .="</li>";
	}
}

function Datas($seid=0){
	global $html,$_SGLOBAL;
	$html .="<ul>";
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('arctype')." WHERE reid =".$seid." ORDER BY tptime");
	while($value = $_SGLOBAL['db']->fetch_array($query)) {
		$seid = $value['lid'];
		$html .="<li><span>".$value['typename']."(ID:".$seid.")</span>|<a href='admincp.php?ac=arctype&op=add&reid=".$value['lid']."'>添加子栏目</a>|<a href='admincp.php?ac=arctype&op=edit&lid=".$value['lid']."'>修改栏目</a>|<a class='del' ref='admincp.php?ac=arctype&op=del&lid=".$value['lid']."'>删除栏目</a>|";
		Datas($seid);
		$html .="</li>";
	}
	$html .="</ul>";
}
?>